<template>
  <div>
    <el-dialog
      title="编辑器"
      :visible="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <CodeMode
        v-init-screen-h="150"
        ref="aceRef"
        v-model="dataValue"
        language="dockerfile"
      ></CodeMode>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose()">取 消</el-button>
        <el-button type="primary" @click="handleSum()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import CodeMode from "@/components/Aceeditor/CodeEditor.vue";
import { edgeWrite } from "@/api/siddhi";
import { base64EncodeUnicode, base64DecodeUnicode } from "@/utils/utils";
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      dataValue: "",
    };
  },
  components: {
    CodeMode,
  },
  methods: {
    getInput(val) {
      console.log("val :>> ", val);
    },
    handleSum() {
      console.log("param :>> ", this.$store.getters.activeTab);
      var fileNameBase64 = base64EncodeUnicode(
        this.$store.getters.activeTab.name + ".siddhi"
      );
      const codeBase64 = base64EncodeUnicode(this.$refs.aceRef.getValue());
      var workspace64 = base64EncodeUnicode("workspace");
      var param =
        "location=" +
        workspace64 +
        "&configName=" +
        fileNameBase64 +
        "&config=" +
        codeBase64;
      //调用写入接口
      edgeWrite(param).then((res) => {
        this.$store.commit("siddhi/SET_LOG_DATA", {
          message: "【" + this.$store.getters.activeTab.name + "】保存成功!",
          type: "INFO",
        });
        this.$store.commit("siddhi/SET_CONSOLE_OPEN", true);
        this.$store.dispatch("siddhi/loadWorkspaceTree");
        this.$emit("codeSubmit", this.$store.getters.activeTab.name);
        this.handleClose();
      });
    },
    handleClose() {
      this.$emit("update:dialogVisible", false);
    },
    aceSetValue(val) {
      this.dataValue = val;
    },
  },
};
</script>

<style>
</style>